import { Delete } from "@/http/http";
import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { FileInfo } from "./types";

/**
 * 上传文件
 *
 * @param file
 */
export function uploadFileApi(file: File): AxiosPromise<FileInfo> {
  const formData = new FormData();
  formData.append("file", file);
  return request({
    url: "/api/v1/files",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

/**
 * 删除文件
 *
 * @param filePath 文件完整路径
 */
export function deleteFileApi(filePath?: string) {
  return request({
    url: "/api/v1/files",
    method: "delete",
    params: { filePath: filePath },
  });
}

/**
 * 文件-根据id-删除
 * @param id
 */
export function deleteById(id: string) {
  return Delete("/api/v1/minio/deleteById/" + id);
}
/**
 * 文件-根据id数组-删除
 * @param id
 */
export function deleteByIds(ids: string[]) {
  return Delete("/api/v1/minio/deleteByIds/" + ids);
}
